package com.jucai.pppeiyouclient.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.jucai.pppeiyouclient.R;
import com.jucai.pppeiyouclient.base.CommonRecyclerViewAdapter;
import com.jucai.pppeiyouclient.bean.OrderBean;
import com.jucai.pppeiyouclient.view.activity.CommonH5Activity;

import java.util.List;


public class OrderListAdapter extends CommonRecyclerViewAdapter<OrderBean> {

    public OrderListAdapter(Context context, List<OrderBean> data) {
        super(context, data);
    }

    @Override
    public void bindHolder(CommonHolder holder, final OrderBean orderBean) {

        holder.setIsRecyclable(false);

        holder.setImage(R.id.order_user_img, orderBean.getMember_avatar(), 60, 60);

        if (TextUtils.isEmpty(orderBean.getMember_realname())) {
            String phone = orderBean.getMember_phone();
            String temp = phone.substring(0, 3) + "****" + phone.substring(7, 11);
            holder.setText(R.id.order_user_name, temp);
        } else {
            holder.setText(R.id.order_user_name, orderBean.getMember_realname());
        }

        if (TextUtils.equals(orderBean.getMember_sexual(),"男")) {
            ImageView imageView = holder.getView(R.id.order_user_gender);
            imageView.setImageResource(R.drawable.ic_gender_boy_order);
        } else {
            ImageView imageView = holder.getView(R.id.order_user_gender);
            imageView.setImageResource(R.drawable.ic_gender_girl_order);
        }

        if (TextUtils.equals(orderBean.getMember_age(),"0")) {
            holder.setText(R.id.order_user_info, "");
            holder.setGone(R.id.order_user_gender);
        } else {
            holder.setText(R.id.order_user_info, orderBean.getMember_age());
        }

        holder.setText(R.id.order_create_time, orderBean.distance);

        holder.setText(R.id.order_start_time, "开始日期：" + orderBean.getTorder_start_time().replace("-", "/"));

        holder.setText(R.id.order_see_address, "见面地点：" + orderBean.getTorder_start_point());


        RelativeLayout relativeLayout = holder.getView(R.id.main_relative_layout);

        relativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CommonH5Activity.startCommH5(mContext, 1, orderBean.getURL(), null, orderBean.getTorder_id(), null);
            }
        });

    }

    @Override
    protected int getItemType(int position) {
        return 0;
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_order_layout_list;
    }

}
